package com.hgyc.mom.base.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.hgyc.mom.base.mapper.SupplierMapper;
import com.hgyc.mom.base.entity.Supplier;
import com.hgyc.mom.base.service.SupplierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import com.hgyc.mom.common.exception.BizException;

/**
 * 供应商Service业务层实现
 *
 * @author fwj
 * @since 2025-05-15
 */
@Slf4j
@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {


    /**
     * {@inheritDoc}
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String importData(List<Supplier> supplierList, boolean updateSupport) {
        if (supplierList == null || supplierList.isEmpty()) {
            throw new IllegalArgumentException("导入数据不能为空");
        }

        try {
            if (updateSupport) {
                // TODO 实现更新已有数据的导入逻辑
                return "更新导入成功，共导入 " + supplierList.size() + " 条数据";
            } else {
                // TODO 实现不更新已有数据的导入逻辑
                return "新增导入成功，共导入 " + supplierList.size() + " 条数据";
            }
        } catch (Exception e) {
            log.error("供应商导入失败", e);
            throw new BizException("供应商导入失败：" + e.getMessage());
        }
    }
}